<h1>Listing invoices</h1>

<br/>
<% form_tag :action => 'filter' do %>
<table>
  <tr>
    <td class="form_label_cell">Issue date</td>
    <td>from <%= date_select("filter", "issue_date_from", :start_year => 2000, :use_month_numbers => true, :prompt => { :day => 'D', :month => 'M', :year => 'Y' }) %></td>
	<td>to <%= date_select("filter", "issue_date_to", :start_year => 2000, :use_month_numbers => true, :prompt => { :day => 'D', :month => 'M', :year => 'Y' }) %></td>
  </tr>
  <tr>
    <td class="form_label_cell">Selling date</td>
	<td>from <%= date_select("filter", "selling_date_from", :start_year => 2000, :use_month_numbers => true, :prompt => { :day => 'D', :month => 'M', :year => 'Y' }) %></td>
	<td>to <%= date_select("filter", "selling_date_to", :start_year => 2000, :use_month_numbers => true, :prompt => { :day => 'D', :month => 'M', :year => 'Y' }) %></td>
  </tr>
  <tr>
    <td class="form_label_cell">Due date</td>
	<td>from <%= date_select("filter", "due_date_from", :start_year => 2000, :use_month_numbers => true, :prompt => { :day => 'D', :month => 'M', :year => 'Y' }) %></td>
	<td>to <%= date_select("filter", "due_date_to", :start_year => 2000, :use_month_numbers => true, :prompt => { :day => 'D', :month => 'M', :year => 'Y' }) %></td>
  </tr>
  <tr>
    <td class="form_label_cell">Number</td>
    <td><%= text_field("filter", "number", :size => 15) %></td>
    <td class="form_label_cell">Corrects</td>
    <td><%= text_field("filter", "corrects", :size => 15) %></td>
  </tr>
  <tr>
    <td class="form_label_cell">Source</td>
	<td><%= select("filter", "source", Transactor.find(:all).collect {|t| [ t.name, t.id ] }, { :include_blank => true }) %></td>
    <td class="form_label_cell">Target</td>
	<td><%= select("filter", "target", Transactor.find(:all).collect {|t| [ t.name, t.id ] }, { :include_blank => true }) %></td>
  </tr>
  <tr>
    <td class="form_label_cell">Payment method</td>
	<td><%= select("filter", "payment_method", %w(cash credit\ card transfer), { :include_blank => true }) %></td>
    <td class="form_label_cell">Creator</td>
	<td><%= select("filter", "creator", Employee.find(:all).collect {|t| [ t.name + " " + t.surname, t.id ] }, { :include_blank => true }) %></td>
  </tr>
  <tr>
    <td class="form_label_cell">Notes</td>
	<td><%= text_field("filter", "notes", :size => 25) %></td>
  </tr>
  <tr>
    <td><input type="submit" value="Filter" /></td>
  </tr>
</table>
<% end %>
<br/><br/>
<table>
  <tr>
    <th>Issue date</th>
	<th>Number</th>
	<th>Corrects</th>
	<th>Source</th>
	<th>Target</th>
    <th>Selling date</th>
    <th>Due date</th>
    <th>Payment</th>
    <th>Notes</th>
	<th>Creator</th>
  </tr>

<% @invoices.each do |invoice| %>
  <tr>
  	<td><%=h invoice.issue_date.strftime('%Y-%m-%d') %></td>
	<td><%=h invoice.number %></td>
	<td><% if invoice.corrected_invoice %>
	  <%= link_to invoice.corrected_invoice.number, invoice.corrected_invoice %>
	<% end %></td>
	<td><% if invoice.source %>
	  <%= link_to invoice.source.name, invoice.source %>
	<% end %></td>
	<td><% if invoice.target %>
	  <%= link_to invoice.target.name, invoice.target %>
	<% end %></td>
    <td><%=h invoice.selling_date %></td>
    <td><%=h invoice.due_date %></td>
    <td><%=h invoice.payment_method %></td>
	<td><%=h truncate(invoice.notes, :length => 20) %></td>
	<td><%=h invoice.employee.name + " " + invoice.employee.surname%></td>
    <td><%= link_to 'Show', invoice %></td>
    <td><%= link_to 'Edit', edit_invoice_path(invoice) %></td>
    <td><%= link_to 'Delete', invoice, :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>
</table>

<br />

<%= link_to 'New invoice', new_invoice_path %>